from rest_framework import serializers
from findMedicine.models import MedicineSystem, MedicineType, MedicineCompany, FindMedicine

# 药品系统序列化器
class MedicineSystemSerializer(serializers.ModelSerializer):
    class Meta:
        model = MedicineSystem
        fields = ['id', 'name']

# 药品类型序列化器
class MedicineTypeSerializer(serializers.ModelSerializer):
    system = MedicineSystemSerializer(read_only=True)  # 药品系统作为外键，只读

    class Meta:
        model = MedicineType
        fields = ['id', 'name', 'system']

# 药品公司序列化器
class MedicineCompanySerializer(serializers.ModelSerializer):
    type = MedicineTypeSerializer(read_only=True)

    class Meta:
        model = MedicineCompany
        fields = ['id', 'name', 'type']

# 药品详情序列化器
class FindMedicineSerializer(serializers.ModelSerializer):
    class Meta:
        model = FindMedicine
        fields = [
            'id', 'title', 'approval_date', 'modification_date', 'Ingredients',
            'Specifications', 'indication', 'Usage_dosage', 'taboo',
            'matters_needing_attention', 'pharmacological_action', 'Pharmacokinetics',
            'chemical_composition', 'listing_authorization_holder', 'manufacturing_enterprise'
        ]
